//闹钟/计时器相关源码


int dalarmtime = 0;
extern bool tapcheck(int);
extern void sleep(int);
//extern tmElements_t ;
extern DateTime nowtime;
extern int Thour;
extern int Tmin;
extern int Tsec;
extern Alarmt alTime;
// int alarmcheck(Alarmt Ti) {

//   int dH = 0;
//   int dM = 0;
//   RTC.read(tm1);
//   Thour = tm1.Hour;
//   Tmin = tm1.Minute;
//   Tsec = tm1.Second;

//   if (Tmin < Ti.aMin) {
//     dM = Ti.aMin + 60 - Tmin;
//     Ti.aHour -= 1;
//   } else if (Tmin >= Ti.aMin) dM = Ti.aMin - Tmin;
//   if (Thour < Ti.aHour) dH = 24 + Ti.aHour - Thour;
//   else if (Thour >= Ti.aHour) dH = Ti.aHour + Thour;
//   return dH * 60 + dM;
// }
#include <string>
using std::string;
const char* alarmifo[4] = {};
void alarmset(int, const char**);
void timerset();
void alarmdesk(const char** alarmifo) {//闹钟主界面
  int alarmselect = 0;
  while (1) {
    display.firstPage();
    display.fillScreen(BackC);
    display.drawInvertedBitmap(xshifting, yshifting, alarmdeskback, 200, 200, FormC);
    alarmifo[3] = (std::__cxx11::to_string(EEPROM.read(6))).c_str();
    Serial.println(alarmifo[3]);
    if (alarmifo[3] != "100" && alarmifo[3] != "255") {
      //Serial.println("kk");
      //Serial.println(alarmifo[3]);

      display.fillRoundRect(150 + xshifting, 25 + yshifting + 47 * atoi(alarmifo[3]), 15, 8, 3, FormC);
    } else if (alarmifo[3] == "255") {
      EEPROM.write(6, 100);
      EEPROM.commit();
      alarmifo[3] = "100";
    }
    Serial.println("*******");
    for (int i = 0; i < 3; i++) {
      string H = (EEPROM.read(2 * i) < 10) ? "0" + std::__cxx11::to_string(EEPROM.read(2 * i)) : std::__cxx11::to_string(EEPROM.read(2 * i));
      string M = (EEPROM.read(2 * i + 1) < 10) ? "0" + std::__cxx11::to_string(EEPROM.read(2 * i + 1)) : std::__cxx11::to_string(EEPROM.read(2 * i + 1));
      alarmifo[i] = (H + ":" + M).c_str();
      Serial.println(alarmifo[i]);
      centerx(alarmifo[i], 36 + i * 47, 1, 30, 100, "否");
    }
    Serial.println("*******");
    if (alarmselect != 0) {
      display.drawRoundRect(90 + xshifting, 50 + yshifting + alarmselect * 47, 20, 3, 1, FormC);
      display.drawRoundRect(90 + xshifting, 50 + yshifting + (alarmselect - 1) * 47, 20, 3, 1, BackC);
    } else {
      display.drawRoundRect(90 + xshifting, 50 + yshifting + alarmselect * 47, 20, 3, 1, FormC);
      display.drawRoundRect(90 + xshifting, 50 + yshifting + 3 * 47, 20, 3, 1, BackC);
    }
    nextPage(10, -1);
    if (espsleep()) continue;
    if (tapcheck(1)) alarmselect = (alarmselect == 3) ? 0 : alarmselect + 1;//闹钟选择
    if (tapcheck(2)) {
      if (alarmselect == 3) {
        return;//返回上一级菜单
      }
      delay(200);
      if (tapcheck(2)) {//长按2进入选择了的闹钟进行设置
        alarmset(alarmselect, alarmifo);//闹钟设置
        display.firstPage();
        display.fillScreen(BackC);
        continue;
      } else {
        if (alarmselect != 3) {//短按2选择启用时钟
          alarmifo[3] = (std::__cxx11::to_string(EEPROM.read(6))).c_str();
          alarmifo[3] = (std::__cxx11::to_string(alarmselect)).c_str();
          EEPROM.write(6, alarmselect);
          EEPROM.commit();
          int Hset = EEPROM.read(2 * alarmselect);
          int Mset = EEPROM.read(2 * alarmselect + 1);
          Serial.println("ccc");
          Serial.println(alarmifo[3]);
          Serial.println(EEPROM.read(6));
          Serial.println("ccc");
          Serial.println("end");
          SPI.end();
          Wire.begin(8, 7);
          RTC.off_alarm();
          Wire.end();
          SPI.begin(7, 8, 8, 6);
          continue;
        }
      }
    }
    if (tapcheck(3)) {//关闭闹钟
      Serial.println("ddd");
      alarmifo[3] == "100";
      EEPROM.write(6, 100);
      EEPROM.commit();
      Serial.println("end");
      SPI.end();
      Wire.begin(8, 7);
      RTC.off_alarm();
      alTime.ok=false;
      //setAlarm(80, 80);
      Wire.end();
      SPI.begin(7, 8, 8, 6);
      continue;
    }
    Serial.println("end");
  }
}
void stopwatch();//计时器
void timepiecedesk() {//闹钟/计时器主界面
  int timepieceselect = 0;
  while (1) {
    display.firstPage();
    display.fillScreen(BackC);
    display.drawInvertedBitmap(xshifting, yshifting, timepieceback, 200, 200, FormC);
    if (timepieceselect != 0) {
      display.drawRoundRect(90 + xshifting, 50 + yshifting + timepieceselect * 47, 20, 3, 1, FormC);
      display.drawRoundRect(90 + xshifting, 50 + yshifting + (timepieceselect - 1) * 47, 20, 3, 1, BackC);
    } else {
      display.drawRoundRect(90 + xshifting, 50 + yshifting + timepieceselect * 47, 20, 3, 1, FormC);
      display.drawRoundRect(90 + xshifting, 50 + yshifting + 3 * 47, 20, 3, 1, BackC);
    }
    nextPage(10, -1);
    if (espsleep()) continue;
    if (tapcheck(1)) timepieceselect = (timepieceselect == 3) ? 0 : timepieceselect + 1;
    if (tapcheck(2)) {
      if (timepieceselect == 0) alarmdesk(alarmifo);//闹钟
      else if (timepieceselect == 1) timerset();//计时器
      else if (timepieceselect == 2) stopwatch();//秒表
      else if (timepieceselect == 3) return;
    }
  }
}
void alarmset(int alarmselect, const char** alarmifo) {//闹钟设定
  display.firstPage();
  display.fillScreen(BackC);
  int timeset[4] = { 0, 0, 0, 0 };
  display.drawInvertedBitmap(xshifting, yshifting, alarmback, 200, 200, FormC);
  u8g2Fonts.setForegroundColor(FormC);
  u8g2Fonts.setBackgroundColor(BackC);
  u8g2Fonts.setFont(chinese_gb2312);
  u8g2Fonts.setCursor(20 + xshifting, 172 + yshifting);
  u8g2Fonts.print("切换/调时");
  u8g2Fonts.setCursor(155 + xshifting, 172 + yshifting);
  u8g2Fonts.print("设定");
  u8g2Fonts.setCursor(155 + xshifting, 25 + yshifting);
  u8g2Fonts.print("退出");
  u8g2Fonts.setForegroundColor(BackC);
  u8g2Fonts.setBackgroundColor(FormC);
  u8g2Fonts.setFont(u8g2_font_logisoso50_tf);
  u8g2Fonts.setCursor(12 + xshifting, 125 + yshifting);
  u8g2Fonts.print(timeset[0]);
  u8g2Fonts.setCursor(56 + xshifting, 125 + yshifting);
  u8g2Fonts.print(timeset[1]);
  u8g2Fonts.setCursor(112 + xshifting, 125 + yshifting);
  u8g2Fonts.print(timeset[2]);
  u8g2Fonts.setCursor(156 + xshifting, 125 + yshifting);
  u8g2Fonts.print(timeset[3]);
  display.drawRoundRect(16 + xshifting, 124 + yshifting, 22, 4, 5, BackC);
  nextPage(10, 2);
  u8g2Fonts.setFont(chinese_gb2312);
  int timechoice = 0;

  while (1) {
    espsleep(1);
    if (tapcheck(1)) {//用于切换和更改时间
      delay(300);
      display.firstPage();
      display.fillScreen(BackC);
      display.drawInvertedBitmap(xshifting, yshifting, alarmback, 200, 200, FormC);
      if (tapcheck(1)) {
        timechoice = (timechoice == 3) ? 0 : timechoice + 1;
        if (timechoice == 0) {
          display.drawRoundRect(10 + 16 + xshifting + 3 * 46, 124 + yshifting, 22, 4, 5, FormC);
          display.drawRoundRect(16 + xshifting + timechoice * 46, 124 + yshifting, 22, 4, 5, BackC);
        } else if (timechoice == 2) {
          display.drawRoundRect(16 + xshifting + (timechoice - 1) * 46, 124 + yshifting, 22, 4, 5, FormC);
          display.drawRoundRect(10 + 16 + xshifting + timechoice * 46, 124 + yshifting, 22, 4, 5, BackC);
        } else if (timechoice == 3) {
          display.drawRoundRect(10 + 16 + xshifting + (timechoice - 1) * 46, 124 + yshifting, 22, 4, 5, FormC);
          display.drawRoundRect(10 + 16 + xshifting + timechoice * 46, 124 + yshifting, 22, 4, 5, BackC);
        } else {
          display.drawRoundRect(16 + xshifting + (timechoice - 1) * 46, 124 + yshifting, 22, 4, 5, FormC);
          display.drawRoundRect(16 + xshifting + timechoice * 46, 124 + yshifting, 22, 4, 5, BackC);
        }

      } else {
        if (timechoice == 0) timeset[timechoice] = (timeset[timechoice] == 2) ? 0 : timeset[timechoice] + 1;
        else if (timechoice == 2) timeset[timechoice] = (timeset[timechoice] == 5) ? 0 : timeset[timechoice] + 1;
        else timeset[timechoice] = (timeset[timechoice] == 9) ? 0 : timeset[timechoice] + 1;
      }
      u8g2Fonts.setForegroundColor(FormC);
      u8g2Fonts.setBackgroundColor(BackC);
      u8g2Fonts.setFont(chinese_gb2312);
      u8g2Fonts.setCursor(20 + xshifting, 172 + yshifting);
      u8g2Fonts.print("切换/调时");
      u8g2Fonts.setCursor(155 + xshifting, 172 + yshifting);
      u8g2Fonts.print("设定");
      u8g2Fonts.setCursor(155 + xshifting, 25 + yshifting);
      u8g2Fonts.print("退出");
      u8g2Fonts.setForegroundColor(BackC);
      u8g2Fonts.setBackgroundColor(FormC);
      u8g2Fonts.setFont(u8g2_font_logisoso50_tf);
      u8g2Fonts.setForegroundColor(BackC);
      u8g2Fonts.setBackgroundColor(FormC);
      u8g2Fonts.setCursor(12 + xshifting, 125 + yshifting);
      u8g2Fonts.print(timeset[0]);
      u8g2Fonts.setCursor(56 + xshifting, 125 + yshifting);
      u8g2Fonts.print(timeset[1]);
      u8g2Fonts.setCursor(112 + xshifting, 125 + yshifting);
      u8g2Fonts.print(timeset[2]);
      u8g2Fonts.setCursor(156 + xshifting, 125 + yshifting);
      u8g2Fonts.print(timeset[3]);
      nextPage(10, 2);
    }
    if (tapcheck(2)) {//退出
      return;
    }
    if (tapcheck(3)) {//将输入的时间设定到rtc的闹钟里
      alTime.ok = true;
      alTime.aHour = timeset[0] * 10 + timeset[1];
      alTime.aMin = timeset[2] * 10 + timeset[3];
      SPI.end();
      Wire.begin(8, 7);
      setAlarm(alTime.aMin, alTime.aHour);
      centerx("已设置", 80, 1, 0, 200, "否");
      int dH = 0;
      int dM = 0;
      nowtime = RTC.now();
      Wire.end();
      SPI.begin(7, 8, 8, 6);
      Thour = nowtime.hour();
      Tmin = nowtime.minute();
      Tsec = nowtime.second();


      if (Thour <= alTime.aHour && Tmin <= alTime.aMin) {
        dM = alTime.aMin - Tmin;
        dH = alTime.aHour - Thour;
      } else if (Thour <= alTime.aHour && Tmin > alTime.aMin) {
        dH = alTime.aHour - Thour;
        dM = alTime.aMin - Tmin + 60;
        dH -= 1;
      } else if (Thour > alTime.aHour && Tmin <= alTime.aMin) {
        dM = alTime.aMin - Tmin;
        dH = alTime.aHour - Thour + 24;
      } else if (Thour > alTime.aHour && Tmin > alTime.aMin) {
        dM = alTime.aMin - Tmin + 60;
        dH = alTime.aHour - Thour + 24;
        dH -= 1;
      }

      string dT = (std::__cxx11::to_string(dH) + "小时" + std::__cxx11::to_string(dM) + "分钟后唤醒");


      centerx(dT.c_str(), 100, 1, 0, 200, "否");
      nextPage(10, 2);
      alarmifo[3] = (std::__cxx11::to_string(alarmselect)).c_str();

      EEPROM.write(6, alarmselect);
      EEPROM.write(2 * alarmselect, alTime.aHour);
      EEPROM.write(2 * alarmselect + 1, alTime.aMin);
      //delay(100);
      EEPROM.commit();
      alarmifo[alarmselect] = (std::__cxx11::to_string(EEPROM.read(2 * alarmselect)) + ":" + std::__cxx11::to_string(EEPROM.read(2 * alarmselect + 1))).c_str();
      Serial.println("alarmset");
      Serial.println(alarmifo[alarmselect]);
      Serial.println("alarmset");
      return;
    }
  }
}

void timerset() {//计时器设置（同上）
  display.firstPage();
  display.fillScreen(BackC);
  int timeset[4] = { 0, 0, 0, 0 };
  display.drawInvertedBitmap(xshifting, yshifting, timerback, 200, 200, FormC);
  u8g2Fonts.setForegroundColor(FormC);
  u8g2Fonts.setBackgroundColor(BackC);
  u8g2Fonts.setFont(chinese_gb2312);
  u8g2Fonts.setCursor(20 + xshifting, 172 + yshifting);
  u8g2Fonts.print("切换/调时");
  u8g2Fonts.setCursor(155 + xshifting, 172 + yshifting);
  u8g2Fonts.print("开始");
  u8g2Fonts.setCursor(155 + xshifting, 25 + yshifting);
  u8g2Fonts.print("退出");
  u8g2Fonts.setForegroundColor(BackC);
  u8g2Fonts.setBackgroundColor(FormC);
  u8g2Fonts.setFont(u8g2_font_logisoso50_tf);
  u8g2Fonts.setCursor(12 + xshifting, 125 + yshifting);
  u8g2Fonts.print(timeset[0]);
  u8g2Fonts.setCursor(56 + xshifting, 125 + yshifting);
  u8g2Fonts.print(timeset[1]);
  u8g2Fonts.setCursor(112 + xshifting, 125 + yshifting);
  u8g2Fonts.print(timeset[2]);
  u8g2Fonts.setCursor(156 + xshifting, 125 + yshifting);
  u8g2Fonts.print(timeset[3]);
  display.drawRoundRect(16 + xshifting, 124 + yshifting, 22, 4, 5, BackC);
  nextPage(10, 2);
  u8g2Fonts.setFont(chinese_gb2312);
  int timechoice = 0;

  while (1) {
    int timerM;
    int timerS;
    espsleep(1);
    if (tapcheck(1)) {
      delay(300);
      display.firstPage();
      display.fillScreen(BackC);
      display.drawInvertedBitmap(xshifting, yshifting, timerback, 200, 200, FormC);
      if (tapcheck(1)) {
        timechoice = (timechoice == 3) ? 0 : timechoice + 1;
        if (timechoice == 0) {
          display.drawRoundRect(10 + 16 + xshifting + 3 * 46, 124 + yshifting, 22, 4, 5, FormC);
          display.drawRoundRect(16 + xshifting + timechoice * 46, 124 + yshifting, 22, 4, 5, BackC);
        } else if (timechoice == 2) {
          display.drawRoundRect(16 + xshifting + (timechoice - 1) * 46, 124 + yshifting, 22, 4, 5, FormC);
          display.drawRoundRect(10 + 16 + xshifting + timechoice * 46, 124 + yshifting, 22, 4, 5, BackC);
        } else if (timechoice == 3) {
          display.drawRoundRect(10 + 16 + xshifting + (timechoice - 1) * 46, 124 + yshifting, 22, 4, 5, FormC);
          display.drawRoundRect(10 + 16 + xshifting + timechoice * 46, 124 + yshifting, 22, 4, 5, BackC);
        } else {
          display.drawRoundRect(16 + xshifting + (timechoice - 1) * 46, 124 + yshifting, 22, 4, 5, FormC);
          display.drawRoundRect(16 + xshifting + timechoice * 46, 124 + yshifting, 22, 4, 5, BackC);
        }

      } else {
        if (timechoice == 0) timeset[timechoice] = (timeset[timechoice] == 9) ? 0 : timeset[timechoice] + 1;
        else if (timechoice == 2) timeset[timechoice] = (timeset[timechoice] == 5) ? 0 : timeset[timechoice] + 1;
        else timeset[timechoice] = (timeset[timechoice] == 9) ? 0 : timeset[timechoice] + 1;
      }
      u8g2Fonts.setForegroundColor(FormC);
      u8g2Fonts.setBackgroundColor(BackC);
      u8g2Fonts.setFont(chinese_gb2312);
      u8g2Fonts.setCursor(20 + xshifting, 172 + yshifting);
      u8g2Fonts.print("切换/调时");
      u8g2Fonts.setCursor(155 + xshifting, 172 + yshifting);
      u8g2Fonts.print("设定");
      u8g2Fonts.setCursor(155 + xshifting, 25 + yshifting);
      u8g2Fonts.print("退出");
      u8g2Fonts.setForegroundColor(BackC);
      u8g2Fonts.setBackgroundColor(FormC);
      u8g2Fonts.setFont(u8g2_font_logisoso50_tf);
      u8g2Fonts.setForegroundColor(BackC);
      u8g2Fonts.setBackgroundColor(FormC);
      u8g2Fonts.setCursor(12 + xshifting, 125 + yshifting);
      u8g2Fonts.print(timeset[0]);
      u8g2Fonts.setCursor(56 + xshifting, 125 + yshifting);
      u8g2Fonts.print(timeset[1]);
      u8g2Fonts.setCursor(112 + xshifting, 125 + yshifting);
      u8g2Fonts.print(timeset[2]);
      u8g2Fonts.setCursor(156 + xshifting, 125 + yshifting);
      u8g2Fonts.print(timeset[3]);
      nextPage(10, 2);
    }
    if (tapcheck(2)) {
      return;
    }
    if (tapcheck(3)) {
      timerM = timeset[0] * 10 + timeset[1];
      timerS = timeset[2] * 10 + timeset[3];
      int timertotal = timerS + 60 * timerM;
      int timestart = millis();
      Serial.println(timertotal);
      centerx("已设置", 80, 1, 0, 200, "否");
      display.firstPage();
      display.fillScreen(BackC);
      display.drawInvertedBitmap(xshifting, yshifting, timerback, 200, 200, FormC);
      u8g2Fonts.setForegroundColor(FormC);
      u8g2Fonts.setBackgroundColor(BackC);
      u8g2Fonts.setFont(chinese_gb2312);
      u8g2Fonts.setCursor(20 + xshifting, 172 + yshifting);
      u8g2Fonts.print("暂停");
      u8g2Fonts.setCursor(155 + xshifting, 172 + yshifting);
      u8g2Fonts.print("刷新");
      u8g2Fonts.setCursor(155 + xshifting, 25 + yshifting);
      u8g2Fonts.print("退出");
      while (1) {
        gpio_wakeup_enable(GPIO_NUM_18, GPIO_INTR_LOW_LEVEL);
        gpio_wakeup_enable(GPIO_NUM_19, GPIO_INTR_LOW_LEVEL);
        gpio_wakeup_enable(GPIO_NUM_9, GPIO_INTR_LOW_LEVEL);
        esp_sleep_enable_gpio_wakeup();
        esp_sleep_enable_timer_wakeup(timertotal * 1000000);
        Serial.println("Sleep");
        esp_light_sleep_start();
        if (tapcheck(3)) {
          display.firstPage();
          display.fillScreen(BackC);
          int dtime = (millis() - timestart) / 1000;
          timertotal = timertotal - dtime;
          Serial.println(timertotal);
          timerM = timertotal / 60;  // 将秒数除以60得到分钟数
          timerS = timertotal - timerM * 60;
          timeset[0] = timerM / 10;
          timeset[1] = timerM - timeset[0] * 10;
          timeset[2] = timerS / 10;
          timeset[3] = timerS - timeset[2] * 10;

          for (int i = 0; i < 4; i++) {
            Serial.println(timeset[i]);
          }

          display.drawInvertedBitmap(xshifting, yshifting, timerback, 200, 200, FormC);
          u8g2Fonts.setForegroundColor(FormC);
          u8g2Fonts.setBackgroundColor(BackC);
          u8g2Fonts.setFont(chinese_gb2312);
          u8g2Fonts.setCursor(20 + xshifting, 172 + yshifting);
          u8g2Fonts.print("暂停");
          u8g2Fonts.setCursor(155 + xshifting, 172 + yshifting);
          u8g2Fonts.print("刷新");
          u8g2Fonts.setCursor(155 + xshifting, 25 + yshifting);
          u8g2Fonts.print("退出");
          u8g2Fonts.setFont(u8g2_font_logisoso50_tf);
          u8g2Fonts.setForegroundColor(BackC);
          u8g2Fonts.setBackgroundColor(FormC);
          u8g2Fonts.setCursor(12 + xshifting, 125 + yshifting);
          u8g2Fonts.print(timeset[0]);
          u8g2Fonts.setCursor(56 + xshifting, 125 + yshifting);
          u8g2Fonts.print(timeset[1]);
          u8g2Fonts.setCursor(112 + xshifting, 125 + yshifting);
          u8g2Fonts.print(timeset[2]);
          u8g2Fonts.setCursor(156 + xshifting, 125 + yshifting);
          u8g2Fonts.print(timeset[3]);
          u8g2Fonts.setFont(chinese_gb2312);
          nextPage(10, 2);
          timestart = millis();
          continue;
        } else if (tapcheck(2)) return;
        else if (tapcheck(1)) {
          display.firstPage();
          display.fillScreen(BackC);
          int dtime = (millis() - timestart) / 1000;
          timertotal = timertotal - dtime;
          Serial.println(timertotal);
          timerM = timertotal / 60;  // 将秒数除以60得到分钟数
          timerS = timertotal - timerM * 60;
          timeset[0] = timerM / 10;
          timeset[1] = timerM - timeset[0] * 10;
          timeset[2] = timerS / 10;
          timeset[3] = timerS - timeset[2] * 10;
          display.drawInvertedBitmap(xshifting, yshifting, timerback, 200, 200, FormC);
          u8g2Fonts.setForegroundColor(FormC);
          u8g2Fonts.setBackgroundColor(BackC);
          u8g2Fonts.setFont(chinese_gb2312);
          // u8g2Fonts.setCursor(20 + xshifting, 172 + yshifting);
          // u8g2Fonts.print("继续");
          u8g2Fonts.setCursor(155 + xshifting, 172 + yshifting);
          u8g2Fonts.print("继续");
          u8g2Fonts.setCursor(155 + xshifting, 25 + yshifting);
          u8g2Fonts.print("退出");
          u8g2Fonts.setFont(u8g2_font_logisoso50_tf);
          u8g2Fonts.setForegroundColor(BackC);
          u8g2Fonts.setBackgroundColor(FormC);
          u8g2Fonts.setCursor(12 + xshifting, 125 + yshifting);
          u8g2Fonts.print(timeset[0]);
          u8g2Fonts.setCursor(56 + xshifting, 125 + yshifting);
          u8g2Fonts.print(timeset[1]);
          u8g2Fonts.setCursor(112 + xshifting, 125 + yshifting);
          u8g2Fonts.print(timeset[2]);
          u8g2Fonts.setCursor(156 + xshifting, 125 + yshifting);
          u8g2Fonts.print(timeset[3]);
          u8g2Fonts.setFont(chinese_gb2312);
          nextPage(10, 2);
          gpio_wakeup_enable(GPIO_NUM_18, GPIO_INTR_LOW_LEVEL);
          gpio_wakeup_enable(GPIO_NUM_19, GPIO_INTR_LOW_LEVEL);
          gpio_wakeup_enable(GPIO_NUM_9, GPIO_INTR_LOW_LEVEL);
          esp_sleep_enable_gpio_wakeup();
          Serial.println("Sleep");
          esp_light_sleep_start();
          timestart = millis();
          continue;
        } else if (esp_sleep_get_wakeup_cause() == ESP_SLEEP_WAKEUP_TIMER) {
          display.firstPage();
          display.fillScreen(BackC);
          centerx("计时结束", 64, 1, 0, 200, "否");
          nextPage(10, 2);
          alarmmusic(changtingwai);
          digitalWrite(lightpin, HIGH);
          espsleep(1);
          digitalWrite(lightpin, LOW);
          return;
        }
      }
    }
  }
}

void stopwatch() {
  display.firstPage();
  display.fillScreen(BackC);
  int timeset[4] = { 0, 0, 0, 0 };
  display.drawInvertedBitmap(xshifting, yshifting, timerback, 200, 200, FormC);
  u8g2Fonts.setForegroundColor(FormC);
  u8g2Fonts.setBackgroundColor(BackC);
  u8g2Fonts.setFont(chinese_gb2312);
  // u8g2Fonts.setCursor(20 + xshifting, 172 + yshifting);
  // u8g2Fonts.print("暂停");
  u8g2Fonts.setCursor(155 + xshifting, 172 + yshifting);
  u8g2Fonts.print("开始");
  u8g2Fonts.setCursor(155 + xshifting, 25 + yshifting);
  u8g2Fonts.print("退出");
  u8g2Fonts.setForegroundColor(BackC);
  u8g2Fonts.setBackgroundColor(FormC);
  u8g2Fonts.setFont(u8g2_font_logisoso50_tf);
  u8g2Fonts.setCursor(12 + xshifting, 125 + yshifting);
  u8g2Fonts.print(timeset[0]);
  u8g2Fonts.setCursor(56 + xshifting, 125 + yshifting);
  u8g2Fonts.print(timeset[1]);
  u8g2Fonts.setCursor(112 + xshifting, 125 + yshifting);
  u8g2Fonts.print(timeset[2]);
  u8g2Fonts.setCursor(156 + xshifting, 125 + yshifting);
  u8g2Fonts.print(timeset[3]);
  display.drawRoundRect(16 + xshifting, 124 + yshifting, 22, 4, 5, BackC);
  nextPage(10, 2);
  u8g2Fonts.setFont(chinese_gb2312);

  int timerM = 0;
  int timerS = 0;

  int timertotal = 0;  //timerS + 60 * timerM;
  while (1) {

    espsleep(1);
    if (tapcheck(2)) return;
    else if (tapcheck(3)) {
      int timestart = millis();
      u8g2Fonts.setFont(chinese_gb2312);
      u8g2Fonts.setCursor(20 + xshifting, 172 + yshifting);
      u8g2Fonts.print("暂停");
      u8g2Fonts.setCursor(155 + xshifting, 172 + yshifting);
      u8g2Fonts.print("刷新");
      u8g2Fonts.setCursor(155 + xshifting, 25 + yshifting);
      u8g2Fonts.print("退出");
      nextPage(10, 2);
      while (1) {
        espsleep(1);
        if (tapcheck(1)) {
          display.firstPage();
          display.fillScreen(BackC);
          display.drawInvertedBitmap(xshifting, yshifting, timerback, 200, 200, FormC);
          timertotal = (millis() - timestart) / 1000;
          Serial.println(timertotal);
          timerM = timertotal / 60;  // 将秒数除以60得到分钟数
          timerS = timertotal - timerM * 60;
          timeset[0] = timerM / 10;
          timeset[1] = timerM - timeset[0] * 10;
          timeset[2] = timerS / 10;
          timeset[3] = timerS - timeset[2] * 10;
          u8g2Fonts.setFont(u8g2_font_logisoso50_tf);
          u8g2Fonts.setForegroundColor(BackC);
          u8g2Fonts.setBackgroundColor(FormC);
          u8g2Fonts.setCursor(12 + xshifting, 125 + yshifting);
          u8g2Fonts.print(timeset[0]);
          u8g2Fonts.setCursor(56 + xshifting, 125 + yshifting);
          u8g2Fonts.print(timeset[1]);
          u8g2Fonts.setCursor(112 + xshifting, 125 + yshifting);
          u8g2Fonts.print(timeset[2]);
          u8g2Fonts.setCursor(156 + xshifting, 125 + yshifting);
          u8g2Fonts.print(timeset[3]);
          u8g2Fonts.setFont(chinese_gb2312);
          // u8g2Fonts.setCursor(20 + xshifting, 172 + yshifting);
          // u8g2Fonts.print("暂停");
          u8g2Fonts.setCursor(155 + xshifting, 172 + yshifting);
          u8g2Fonts.print("继续");
          u8g2Fonts.setCursor(155 + xshifting, 25 + yshifting);
          u8g2Fonts.print("退出");
          nextPage(10, 2);
          int timepause = millis();
          while (1) {
            espsleep(1);
            if (tapcheck(3)) {
              timestart = timestart + (millis() - timepause);
              break;
            }
          }
        } else if (tapcheck(2)) return;
        else if (tapcheck(3)) {
          timertotal = (millis() - timestart) / 1000;
          Serial.println(timertotal);
          timerM = timertotal / 60;  // 将秒数除以60得到分钟数
          timerS = timertotal - timerM * 60;
          timeset[0] = timerM / 10;
          timeset[1] = timerM - timeset[0] * 10;
          timeset[2] = timerS / 10;
          timeset[3] = timerS - timeset[2] * 10;
          display.firstPage();
          display.fillScreen(BackC);
          display.drawInvertedBitmap(xshifting, yshifting, timerback, 200, 200, FormC);
          u8g2Fonts.setFont(u8g2_font_logisoso50_tf);
          u8g2Fonts.setForegroundColor(BackC);
          u8g2Fonts.setBackgroundColor(FormC);
          u8g2Fonts.setCursor(12 + xshifting, 125 + yshifting);
          u8g2Fonts.print(timeset[0]);
          u8g2Fonts.setCursor(56 + xshifting, 125 + yshifting);
          u8g2Fonts.print(timeset[1]);
          u8g2Fonts.setCursor(112 + xshifting, 125 + yshifting);
          u8g2Fonts.print(timeset[2]);
          u8g2Fonts.setCursor(156 + xshifting, 125 + yshifting);
          u8g2Fonts.print(timeset[3]);
          u8g2Fonts.setFont(chinese_gb2312);
          u8g2Fonts.setCursor(20 + xshifting, 172 + yshifting);
          u8g2Fonts.print("暂停");
          u8g2Fonts.setCursor(155 + xshifting, 172 + yshifting);
          u8g2Fonts.print("刷新");
          u8g2Fonts.setCursor(155 + xshifting, 25 + yshifting);
          u8g2Fonts.print("退出");
          nextPage(10, 2);
        }
      }
    }
  }
}